package com.xxwu.springlibrary.mapper;

import com.xxwu.springlibrary.model.BookInfo;
import com.xxwu.springlibrary.model.PageRequest;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import javax.websocket.server.PathParam;
import java.awt.print.Book;
import java.util.List;

@Mapper
public interface BookMapper {
    @Insert("insert into book_info(`book_name`,`author`,`count`,`price`,`publish`)" +
            "values(#{bookName},#{author},#{count},#{price},#{publish})")
    Integer insert(BookInfo bookInfo);

    //查询当前图书记录总数
    @Select("select count(1) from book_info where `status`<>0")
    Integer getBookCount();

    //查询当前页的数据
    @Select("select * from book_info where `status`<>0 order by id" +
            " limit #{offset},#{pageSize}")
    List<BookInfo> getBookList(PageRequest pageRequest);

    /*
    根据id查找图书
     */
    @Select("select * from book_info where id = #{id} and `status`<>0")
    BookInfo getBookById(Integer id);

    /*
    修改图书信息
     */
    Integer updateBook(BookInfo bookInfo);

    //批量删除图书操作
    Integer updateBatchBook(@RequestParam List<Integer> ids);
}
